package com.carrental.vehicle.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.carrental.common.result.Result;
import com.carrental.vehicle.entity.ImageCategory;
import com.carrental.vehicle.service.ImageCategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * 图片分类控制器
 */
@Slf4j
@Api(tags = "图片分类管理")
@RestController
@RequestMapping("/image/category")
@RequiredArgsConstructor
public class ImageCategoryController {

    private final ImageCategoryService imageCategoryService;

    /**
     * 分页查询图片分类
     */
    @ApiOperation("分页查询图片分类")
    @GetMapping("/page")
    public Result<IPage<ImageCategory>> pageList(
            @ApiParam("页码") @RequestParam(defaultValue = "1") Integer current,
            @ApiParam("每页数量") @RequestParam(defaultValue = "10") Integer size,
            @ApiParam("分类名称") @RequestParam(required = false) String name,
            @ApiParam("分类编码") @RequestParam(required = false) String code) {
        IPage<ImageCategory> page = imageCategoryService.pageList(current, size, name, code);
        return Result.success(page);
    }

    /**
     * 获取图片分类详情
     */
    @ApiOperation("获取图片分类详情")
    @GetMapping("/{id}")
    public Result<ImageCategory> getById(@ApiParam("分类ID") @PathVariable Long id) {
        ImageCategory category = imageCategoryService.getById(id);
        return Result.success(category);
    }

    /**
     * 新增图片分类
     */
    @ApiOperation("新增图片分类")
    @PostMapping
    public Result<Boolean> add(@ApiParam("图片分类信息") @RequestBody ImageCategory imageCategory) {
        boolean result = imageCategoryService.addCategory(imageCategory);
        return Result.success(result);
    }

    /**
     * 修改图片分类
     */
    @ApiOperation("修改图片分类")
    @PutMapping
    public Result<Boolean> update(@ApiParam("图片分类信息") @RequestBody ImageCategory imageCategory) {
        boolean result = imageCategoryService.updateCategory(imageCategory);
        return Result.success(result);
    }

    /**
     * 删除图片分类
     */
    @ApiOperation("删除图片分类")
    @DeleteMapping("/{id}")
    public Result<Boolean> delete(@ApiParam("分类ID") @PathVariable Long id) {
        boolean result = imageCategoryService.deleteCategory(id);
        return Result.success(result);
    }

    /**
     * 修改图片分类状态
     */
    @ApiOperation("修改图片分类状态")
    @PutMapping("/status")
    public Result<Boolean> updateStatus(
            @ApiParam("分类ID") @RequestParam Long id,
            @ApiParam("状态") @RequestParam Integer status) {
        boolean result = imageCategoryService.updateStatus(id, status);
        return Result.success(result);
    }
} 